﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<ReportModel>" %>
<%@ Import Namespace="ReportService.Models" %>
<%@ Import Namespace="ReportService.Models.ViewModels" %>
<div>
<% using (Ajax.BeginForm("SavePriceBoard", "Report", null, new AjaxOptions { HttpMethod = "post", UpdateTargetId = "ReportViewPlace", OnSuccess = "SaveSuccess" }))
   { %>
    <div class="head">
        <h3>
            PRICE BOARD
        </h3>
    </div>

    <!-- Header -->
    <div class="labelcol"></div>
    <% foreach (PL_TOU_TimeOfUse tou in Model.ListTOU)
       { %>
    <div class="valuecol">
        <div class="title" style="width:96px;text-align:right;">
            <%= tou.TimeOfUse_Name%><br /><br />
            <input type="button" id="btnApplyAll" class="standardButton" value="Apply All" onclick="OnApplyAll(<%= tou.TimeOfUse_ID%>)" />
        </div>        
    </div>
    <% } %>
    <div class="clear_both"></div>

    <!-- Content -->
    <div id="tablePrice">
        <% foreach (GetStoresByNameResult store in Model.ListAllStores)
           { %>
        <div class="labelcol">
            <label><%= store.StoreName%></label> 
        </div>
            <% foreach (PL_TOU_TimeOfUse tou in Model.ListTOU)
               { %>
        <div class="valuecol">
            <% GetListTimeOfUseResult priceboard = Model.PriceBoard.SingleOrDefault(p => p.StoreName == store.StoreName && p.TimeOfUseID == tou.TimeOfUse_ID);
               if (priceboard != null)
               {
               %>
            <%: Html.TextBox("Price", priceboard.Price.Value.ToString("#,0"), new { @id = store.StoreName + "|" + tou.TimeOfUse_ID, @style = "text-align: right; width:90px;" })%>
            <%: Html.Hidden("PriceID", store.StoreName + "|" + tou.TimeOfUse_ID)%>
            <% }
               else
               { %>
            <%: Html.TextBox("Price", "0", new { @id = store.StoreName + "|" + tou.TimeOfUse_ID, @style = "text-align: right; width:90px;" })%>
            <%: Html.Hidden("PriceID", store.StoreName + "|" + tou.TimeOfUse_ID)%>
            <% } %>
        </div>
            <% } %>
        <div class="clear_both"></div>
        <% } %>
    </div>
    
    <div class="foot">
        <input type="button" id="btnOK" class="standardButton" value="OK" onclick="OnSavePriceBoard()" />
        <input type="button" id="btnClear" class="standardButton" value="Clear" onclick="OnClearPrices()" />
        <input type="submit" id="hiddenSubmitPrice" style="display:none;" />
        <img id = "loaderImg" src="../../Content/images/ajax-loader.gif" alt="" title="" style="display:none;" />
    </div>

    <script language="javascript" type="text/javascript">
        function OnSavePriceBoard() {
            $('#loaderImg').show();
            $("#hiddenSubmitPrice").click();
        }
        function OnClearPrices() {
            $("input[name=Price]").val('0');
        }
        function OnApplyAll(touID) {
            var price = prompt("Please input the price");
            if (price != null) {
                if (isDecimal(price)) {
                    $('input[id$=\\|' + touID + ']').val(addCommas(price));
                }
            }
        }
        function SaveSuccess() {
            $('#loaderImg').hide();
        }
    </script>
<% } %>
</div>